#include <stdlib.h>
#include <stdio.h>
#define SIZE 10

typedef int ElemType;
typedef struct{
    ElemType *base;
    int front;
    int rear;
}SqQueue;

void init(SqQueue &Q){
    Q.base = (ElemType *) malloc(SIZE * sizeof(ElemType));
    if(!Q.base){
        exit(0);
    }
    Q.front = Q.rear = 0;
}

void getLength(SqQueue Q, int &len){
    len = (Q.rear - Q.front + SIZE) % SIZE;
}

bool enter(SqQueue &Q, ElemType e){
    if((Q.rear - Q.front + SIZE) % SIZE == SIZE -1){
        return false;
    }
    Q.base[Q.rear] = e;
    Q.rear = (Q.rear + 1) % SIZE;
    return true;
}

bool remove(SqQueue &Q, ElemType &e){
    if(Q.rear == Q.front){  //队空
        return false;
    }
    e = Q.base[Q.front];
    Q.front = (Q.front + 1) % SIZE;
    return true;
}

void printQueue(SqQueue Q){
    int f = Q.front;
    int r = Q.rear;
    if(r < f){
        for(int i = f; i < SIZE; i++){
            printf("%d<-", Q.base[i]);
        }
        for(int i = 0; i < r; i++){
            printf("%d", Q.base[i]);
            if(i != r - 1){
                printf("<-");
            }
        }
    }else if (r > f){
        for(int i = f; i < r; i++){
            printf("%d", Q.base[i]);
            if(i != r - 1){
                printf("<-");
            }
        }
    }else{
        printf("这是一个空队列!\n");
    }
}
bool isEmpty(SqQueue Q){
    return Q.rear == Q.front;
}